package pers.qianyu.month_202102.date_20210225;

import pers.qianyu.util.model.*;

/**
 * 112. 路径总和
 * https://leetcode-cn.com/problems/path-sum/
 *
 * @author mizzle rain
 * @date 2021-02-25 17:56
 */
public class HasPathSum {
    boolean res = false;

    public boolean hasPathSum(TreeNode root, int target) {
        if (root == null) return false;
        recur(root, target);
        return res;
    }

    private void recur(TreeNode root, int target) {
        if (root.left == null && root.right == null) {
            if (target == root.val) {
                res = true;
            }
            return;
        }
        if (root.left != null) recur(root.left, target - root.val);
        if (root.right != null) recur(root.right, target - root.val);
    }
}
